******************************
*Table A9: School-level heterogeneity, by school attendance rate 
************************
clear all
set trace off
set more off
use school_heterogeneity_attendance, clear
collapse(mean) treat total_attendance_2_help, by(school_id)
rename total_attendance_2_help school_level_att
merge 1:m school_id using Jehanabad_analytic_sample_hemoglobin.dta
**mean =74.8, median 76.3
g school_high= (school_level_att> 0.748)  /* based on aggregated child level endline attendance data */
label var any_an "Any anemia"
label var hemoglobin "Hemoglobin"

global socio_cov_4_vari no_HHmembers years_schooling_father years_schooling_mother asset_index

global school_cov_4_vari total_enrollment class_size student_teacher_ratio

***panel A; Above mean school attendance 
eststo clear

foreach var in hemoglobin any_an mild_an mod_sev_an {
xtset child_unique wave
eststo: xtreg `var' treat##wave $socio_cov_4_vari $school_cov_4_vari if school_high==1, fe cluster (school_id)
}
esttab using table9_panelA.csv, se keep(1.treat#1.wave) varwidth(35) nobaselevels interaction(" X ") b(a3) star(* 0.10 ** 0.05 *** 0.01) replace ///
coeflabels(1.treat#1.wave "Treat*post" ) nonotes title(Table A9: School-level heterogeneity, by school attendance rate) ///
order(1.treat#1.wave 1.wave) label


***panel B; Below mean school attendance 
eststo clear
foreach var in hemoglobin any_an mild_an mod_sev_an {
xtset child_unique wave
eststo: xtreg `var' treat##wave $socio_cov_4_vari $school_cov_4_vari if school_high==0, fe cluster (school_id)
}

esttab using table9_panelA.csv, se keep(1.treat#1.wave) varwidth(35) nobaselevels interaction(" X ") b(a3) star(* 0.10 ** 0.05 *** 0.01) ///
coeflabels(1.treat#1.wave "Treat*post" 1.wave) nonotes title(Table A9: School-level heterogeneity, by school attendance rate) ///
order(1.treat#1.wave 1.wave) label append





